<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript">
	function check_input(form)
	{
            if(form.mingcheng.value=="") {
                alert("请输入图书名称!");
		form.mingcheng.select();
		return(false);
            }
           
	  if(form.jinjia.value=="") {
	     alert("请输入图书进价!");
		 form.jinjia.select();
		 return(false);
	   }
           
	  if(form.danjia.value=="") {
	     alert("请输入图书单价!");
		 form.danjia.select();
		 return(false);
	   }
           
           if(form.leixing.value==0) {
	     alert("请选择图书类型!");
		 return(false);
	   }
           
	   if(form.shuliang.value=="") {
	     alert("请输入图书数量!");
		 form.shuliang.select();
		 return(false);
	   }
           
	   return(true);
	}
        </script>
    </head>
    <body>
        <?php
        // put your code here
        /**
         * @todo 把相应的字段写入到数据库中
         * @todo 添加对图书图片的修改
         */
        include ("../conn/conn.php");
        include ("./br2nl.php");
        
        $conn = prepare();
        $stmt = exectue_sql_statement($conn, "select Book.*, book_amount ".
                                             "from Book, Store ".
                                             "where Book.book_id=Store.book_id and Book.book_id=".$_GET['book_id']);
        $info1=sqlsrv_fetch_array($stmt);
        ?>
        <table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td height="20" bgcolor="#B0E0E6">
                    <div align="center">
                        修改图书信息
                    </div>
                </td>
            </tr>
            <tr>
                <td height="253" bgcolor="#666666">
                    <table width="720" border="0" cellpadding="0" cellspacing="1">
                        <form name="form1" enctype="multipart/form-data" method="post" action="savechangedbook.php?book_id=<?php echo $_GET['book_id'];?>" onSubmit="return check_input(this)">
                            <tr>
                                <td width="129" height="25" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书名称：
                                    </div>
                                </td>
                                <td width="618" bgcolor="#FFFFFF">
                                    <div align="left">
                                        <input type="text" name="mingcheng" size="20" maxlength="18" value="<?php echo $info1['book_name'];?>">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="center">
                                        价格：
                                    </div>
                                </td>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="left">
                                        进价：
                                        <input type="number" name="jinjia" size="3" maxlength="3" max="999" min="1" step="0.01" value="<?php echo $info1['purchase_price'];?>">
                                        元&nbsp;&nbsp;单价：
                                        <input type="number" name="danjia" size="3" maxlength="3" max="999" min="1" step="0.01" value="<?php echo $info1['unit_price'];?>">
                                        元
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书类型：
                                    </div>
                                </td>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="left">
                                    <?php
                                    $stmt = exectue_sql_statement($conn, "select * from Classification");
                                    $info = sqlsrv_fetch_array($stmt);
                                    if($info == false) {
                                        echo "请先添加图书类型!";
                                    } else {
                                    ?>
                                    <select name="leixing">
                                    <?php
                                    do {
                                    ?>
                                    <option value=<?php echo $info['classify_id'];?>
                                    <?php if($info1['classify_id']==$info['classify_id']){echo "selected";}?>
                                    >
                                    <?php echo $info['classify_name'];?>
                                    </option>
                                    <?php
                                    } while($info = sqlsrv_fetch_array($stmt));
                                    ?>  
                                    </select>
                                    <?php
                                    }
                                    ?>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td width="129" height="25" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书作者：
                                    </div>
                                </td>
                                <td width="618" bgcolor="#FFFFFF">
                                    <div align="left">
                                        <input type="text" name="author" size="20" maxlength="18" value="<?php echo $info1['book_author'];?>">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书数量：
                                    </div>
                                </td>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="left">
                                        <input type="number" name="shuliang" size="5" maxlength="4" max="9999" min="1" value="<?php echo $info1['book_amount'];?>">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td height="80" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书简介：
                                    </div>
                                </td>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="left">
                                        <textarea name="jianjie" cols="80" rows="8" maxlength="450"><?php echo br2nl($info1['book_introduction']);?>
                                        </textarea>
                                </div></td>
                            </tr>
                            <tr>
                                <td height="80" bgcolor="#FFFFFF">
                                    <div align="center">
                                        图书目录：
                                    </div>
                                </td>
                                <td height="25" bgcolor="#FFFFFF">
                                    <div align="left">
                                        <textarea name="mulu" cols="80" rows="8" maxlength="450"><?php echo br2nl($info1['book_catalog']);?>
                                        </textarea>
                                </div></td>
                            </tr>
                            <tr>
                              <td height="25" colspan="2" bgcolor="#FFFFFF">
                                  <div align="center">
                                      <input name="submit" type="submit" id="submit" value="修改">
                                      &nbsp;&nbsp;
                                      <input type="reset" value="重置">
                                  </div>
                              </td>
                            </tr>
                    </form>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>
